
component accessors="true" output="false" extends="AbsDelegate"
{

	property name="UserFactory" type="it.millemultimedia.easyBlog.factory.UserFactory";

	public it.millemultimedia.easyBlog.delegate.UserDelegate function init( required Any dataObject ){
		
		variables.dataObject = arguments.dataObject;
		
		return this;
	}
	
	public it.millemultimedia.easyBlog.validator.UserValidator function getValidator(){
		
		return getUserFactory().getValidator();
	}
	
	public it.millemultimedia.easyBlog.model.User function createInstance(){
		
		return getUserFactory().createInstance();
	}

	public void function create( required Any User ){
		
		variables.dataObject.create( arguments.User );
		
	}

	public void function update( required Any User ){
		
		variables.dataObject.update( arguments.User );
		
	}

	public it.millemultimedia.easyBlog.model.User function read( required Any User, Boolean lazy="true" ){
	
		var idUser = "" ;
		var Users = variables.dataObject.read( arguments.User );
		var permissions = queryNew( 'idPremission' );
		var preferences = queryNew( 'idPreference' );
		
		if( arguments.lazy eq false ){
		
			if( Users.recordcount ){

				idUser = valueList( Users.idUser );
			
				permissions = getPermissions( idUser );
			
				preferences = getPreferences( idUser );
				
			}
		
		}
		
		User = getUserFactory().get( Users, permissions, preferences );
		
		return User;
		
	}

	public void function delete( required Any User ){
		
		variables.dataObject.delete( arguments.User );
		
	}

	public it.millemultimedia.easyBlog.model.User[] function list( required Any User, Boolean lazy="true", Numeric start=0, Numeric count=0 ){
	
		var list = "";
		var idUser = "" ;
		var Users = variables.dataObject.list( arguments.User );
		var permissions = queryNew( 'idPremission' );
		var preferences = queryNew( 'idPreference' );
		
		if( arguments.lazy eq false ){
		
			if( Users.recordcount ){

				idUser = valueList( Users.idUser );
			
				permissions = getPermissions( idUser );
			
				preferences = getPreferences( idUser );
				
			}
		
		}

		list = getUserFactory().list( Users, permissions, preferences, arguments.start, arguments.count );
		
		return list;
		
	}

	private Query function getPermissions( required String idUser ){
		
		return variables.dataObject.getPermissions( arguments.idUser );
		
	}

	private Query function getPreferences( required String idUser ){
		
		return variables.dataObject.getPreferences( arguments.idUser );
		
	}

}
